package com.ljh.ad.controller;

import com.ljh.ad.ad.dump.DConstant;
import com.ljh.ad.service.DumpDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author ljh
 * @create 2020/3/6
 * @describe
 */
@Component
@Order(value = 1)
@Slf4j
public class StartRunner implements CommandLineRunner {

    public static void main(String[] args) {
        System.out.println(String.format("%s%s", DConstant.DATA_ROOT_DIR,
                DConstant.AD_PLAN));
    }

    @Autowired
    DumpDataService dumpDataService;
    @Override
    public void run(String... args) throws Exception {
        log.info("start init data");
        //初始化数据到文件
        dumpDataService.dumpAdPlanTable(
                String.format("%s%s", DConstant.DATA_ROOT_DIR,
                        DConstant.AD_PLAN)
        );
        dumpDataService.dumpAdUnitTable(
                String.format("%s%s", DConstant.DATA_ROOT_DIR,
                        DConstant.AD_UNIT)
        );
        dumpDataService.dumpAdCreativeTable(
                String.format("%s%s", DConstant.DATA_ROOT_DIR,
                        DConstant.AD_CREATIVE)
        );
        dumpDataService.dumpAdCreativeUnitTable(
                String.format("%s%s", DConstant.DATA_ROOT_DIR,
                        DConstant.AD_CREATIVE_UNIT)
        );
        dumpDataService.dumpAdUnitDistrictTable(
                String.format("%s%s", DConstant.DATA_ROOT_DIR,
                        DConstant.AD_UNIT_DISTRICT)
        );
        dumpDataService.dumpAdUnitItTable(
                String.format("%s%s", DConstant.DATA_ROOT_DIR,
                        DConstant.AD_UNIT_IT)
        );
        dumpDataService.dumpAdUnitKeywordTable(
                String.format("%s%s", DConstant.DATA_ROOT_DIR,
                        DConstant.AD_UNIT_KEYWORD)
        );

        log.info("finish init data");
    }
}
